﻿#pragma once
#include "../ted/ted.h"

using namespace TED;
// 연산자 오버로딩, Friend 키워드

class OperatorOveroading
{
public:
	int a;
	int b;
	OperatorOveroading() {
	};
	OperatorOveroading(int a, int b) {
		this->a = a;
		this->b = b;
		//Logger::Get().Debug(_T("OperatorOveroading 생성자 호출"));
	};
	~OperatorOveroading(void) {
		//Logger::Get().Debug(_T("OperatorOveroading 소멸자 호출"));
	};

	// 복사 생성자
	OperatorOveroading(const OperatorOveroading& oop) {
		//Logger::Get().Debug(_T("OperatorOveroading 복사 생성자 호출"));
	};
	void Test() {
		OperatorOveroading op1(1,1);
		OperatorOveroading op2(1,1);
		OperatorOveroading op3 = op1 + op2;
		op3.Print();
		int value = op3[3];
	};

	void Print() {
		//Logger::Get().Debug(_T("a=%d, b=%d"),a,b);
		
	}

	// + 오버로딩
	// void operator+(OperatorOveroading oor)
	const OperatorOveroading operator+(const OperatorOveroading& oor) {
		//Logger::Get().Debug(_T("OperatorOveroading + 연산자 오버로딩 호출"));
		OperatorOveroading oor2(1,1);
		oor2.a = this->a +1;
		oor2.b = this->b +1;
		return oor2;
	};

	// 배열 오버로딩
	int operator[](int index) const {
		if(index==0) return a;
		else if(index==1) return b;
		else {
			throw "Threre is no value.";
		}
	};

	// 멤버변수가 private 인경우 friend를 이용한다.
	// friend const OperatorOveroading operator-(const OperatorOveroading& oor1, const OperatorOveroading& oor2); // friend 메소드
	// friend class B  // friend 클래스( B클래스에서는 A클래스의 멤버함수들을 접근가능)
};

//전역함수 이용 오버로딩
const OperatorOveroading operator-(const OperatorOveroading& oor1, const OperatorOveroading& oor2) {
	int a = oor1.a -  oor2.a;
	int b = oor1.b -  oor2.b;
	return OperatorOveroading(a,b);
};

